<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1;IE=edge">
    <meta name="viewport" content="user-scalable=no">
    <!-- vue2 -->
    <script src="/examples/js/vue.min.js"></script>
    <!-- 示例演示-公共样式 -->
    <link rel="stylesheet" href="/examples/css/railView.css" type="text/css" />
    <!-- 引入element-ui组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- RailUnit 插件 -->
    <script type="text/javascript" src="/RailUnit/RailUnit.umd.js" charset="utf-8"></script>
    <!-- RailUnit 样式 -->
    <link rel="stylesheet" href="/RailUnit/RailUnit.umd.css" type="text/css">
</head>
<body>
    <div id="app">
        <div id="buttom-container">
            <el-button type="info" size="small" id="shadowBtn" @click="isShadow">开启倒影</el-button>
            <el-button type="info" size="small" @click="showCard = true">设置倒影</el-button>
            <el-button type="info" size="small" @click="optimget">获取参数</el-button>
            <el-button type="info" size="small" @click="resetToDefault">恢复默认</el-button>
        </div>
        <el-card class="box-card" v-show="showCard" style="width: 400px;">
            <div slot="header" class="clearfix">
              <span>设置</span>
              <el-button class="close-btn" type="text" @click="showCard = false">×</el-button>
            </div>
            <div class="card-container">
                <el-form 
                    ref="form" 
                    :model="formValues" 
                    label-width="110px"
                >
                    <el-form-item label="倒影透明度：">
                        <el-input v-model.number="formValues.opacity" placeholder="可输入0-1"></el-input>
                    </el-form-item>
                    <el-form-item label="倒影淡出角度：">
                        <el-input v-model.number="formValues.angle"></el-input>
                    </el-form-item>
                    <el-form-item label="倒影虚化直径：">
                        <el-input v-model.number="formValues.diameter" placeholder="请输入阴影分辨率"></el-input>
                    </el-form-item>
                </el-form>
                <div class="modal-footer">
                    <el-button size="small" type="primary" @click="handleSubmit">确认</el-button>
                </div>
            </div>
        </el-card>
        <div id="viewer" style="width:100%;height:100%;position:relative;float:left"></div>
    </div>

    <script id="viewerStartup" type="module">
        const vm = new Vue({
            el: '#app',
            data: {
                bimViewer: null,
                formRef: null,
                showCard: false,
                formValues: {
                    opacity: 0.5,
                    angle: 500,
                    diameter: 1
                }

            },
            mounted () {
                this.bimViewerFn()
            },
            methods: {
                // 初始化模型
                bimViewerFn() {
                    this.bimViewer = new MyViewer({
                        serverUrl: '/RailUnit/',
                        containerElement: document.getElementById('viewer'),
                        nodeVisible: false
                    })
                    this.bimViewer.loadModel2('jianzhu')
                },
                isShadow() {
                    const shadowBtn = document.getElementById("shadowBtn");
                    console.log(shadowBtn);
                    if (shadowBtn.innerText === "开启倒影") {
                        this.bimViewer.enableReflection(true);
                        shadowBtn.innerText ="关闭倒影"
                    } else {
                        this.bimViewer.enableReflection(false);
                        shadowBtn.innerText ="开启倒影"
                    }
                },
                handleSubmit () {
                    const { opacity, angle, diameter } = this.formValues
                    console.log(this.formValues, 'this.formValues');
                    this.bimViewer.setReflection(opacity, angle, diameter);
                },
                resetToDefault () {
                    let res = this.bimViewer.resetDefaultReflection();
                    console.log(res);
                },
                optimget () {
                    let res = this.bimViewer.getReflectionSettion();
                    console.log(res);
                    var description = ""; 
                    for(var i in res){ 
                        var property = '';
                        if (typeof res[i] === 'object') {
                            property = JSON.stringify(res[i])
                        } else {
                            property = res[i]
                        }
                        description += i + " = " + property + " \n"; 
                    } 
                    alert(description); 
                }
            }
        })  
    </script>
</body>
</html>
